import os
import sys
import re

if __name__ == '__main__':
    handler = sys.stdin
    word_dict = {}
    for line in handler:
        # print(line)
        
        host = line.strip().split(' ')[2]

        if host not in word_dict.keys():
            frends_s = set()
            frends_s.add(line.strip().split(' ')[0])
            frends_s.add(line.strip().split(' ')[1])
            word_dict[host] = frends_s
        else:
            frends_s = word_dict[host]
            frends_s.add(line.strip().split(' ')[0])
            frends_s.add(line.strip().split(' ')[1])



  

    for j in word_dict:
        print(j, word_dict[j])

